<?php

   /**
    *
    * FILE:          monthlyISR.php
    * LOCATION:      /root/forms/
    * REFERENCES:    none 
    * FUNCTION:          
    * DEPENDENCIES: 
    *
    *                
    * 
    * ==============================================================================
    * 
    * @version $Id: nav.php,v 0.1 2007/09/3
    * @copyright Copyright (c) none
    * @author ChrisV
    * @license http://opensource.org/licenses/gpl-license.php GNU General 
    * Public License (GPL)
    * 
    * ==============================================================================
    * 
    */


   //connect to db
   include('includes/db_connect.php');
	
	//this is the CASENOTE ID
	$isrId= $_GET['isrId'];
	if(!$isrId){
		$isrId = 0;
		$case_note_header ="New Consumer Case Note Entry ";
	}else{
		$case_note_header ="You Are Editing Consumer Case Note #".$isrId.". ";
	}
	//unset $serviceHours;
	
	//information and referral id
	$irId = $_GET['irId'];
	//CONSUMER ID
	$id = $_GET['id'];

//lets get the niceform helper
?>

<script type="text/javascript" src="helpers/niceedit/nicEdit.js"></script>
<script type="text/javascript">
	bkLib.onDomLoaded(function() { nicEditors.allTextAreas() });
</script>

<?php
//echo "<h1>isrID".$isrId."</h1>";

$query2 = "select * from consumer where id = ".$id;
$row2 = mysql_fetch_array(mysql_query($query2));
$consumerSiganture = $row2["first_name"]." ".$row2["last_name"];

$query = "select * from monthlyISR where consumer_id = ".$id." and id = ".$isrId;
$result = mysql_query($query);
if($row = mysql_fetch_array($result)) {
	$misrId = $row["id"];
	$caseNoteMonth = $row["case_note_month"];
	$caseNoteYear = $row["case_note_year"];
	$caseNoteCoordinator = $row["case_note_coordinator"];
	$serviceType = $row["service_type_id"];
	$totalServiceContacts = $row["total_service_contacts"];
	$contactByPerson = $row["contact_by_person"];
	$contactByPhone = $row["contact_by_phone"];
	$contactByMail = $row["contact_by_mail"];
	$services = $row["services"];
	$serviceHourTotals = $row["service_hour_totals"];
} 
?>

<form action="actions/ProcessMonthlyISR.php" method="post">
  <div style="border:1px #ddd solid;padding:3px;">
    <h2><?=$case_note_header;?></h2>
    <table class="table2" id="monthlyISRTbl">
      <tbody>
        <tr>
          <td colspan="3"><h3>Case Note Data</h3></td>
        </tr>
        <tr>
          <td colspan="2"><label name="caseNoteMonth">Case Note Month</label>
            <br>
            <select name="caseNoteMonth" id="caseNoteMonth" style="width: 150px;">
              <option value=""> --- </option>
              <option value="01">January</option>
              <option value="02">February</option>
              <option value="03">March</option>
              <option value="04">April</option>
              <option value="05">May</option>
              <option value="06">June</option>
              <option value="07">July</option>
              <option value="08">August</option>
              <option value="09">September</option>
              <option value="10">October</option>
              <option value="11">November</option>
              <option value="12">December</option>
            </select>
            <script>					
						for(i=0; i<$('caseNoteMonth').options.length; i++) {
							if($('caseNoteMonth').options[i].value=='<? echo $caseNoteMonth ?>') {
								$('caseNoteMonth').options[i].selected = true;
							}
						}
					</script>
          </td>
          <td><label name="caseNoteYear">Case Note Year</label>
            <br>
            <select name="caseNoteYear" id="caseNoteYear" style="width: 150px'">
              <option value=""> --- </option>
              <?php
						
						for($i=0; $i<10; $i++) {
							$year = date("Y", mktime(0,0,0,1,1,date("Y")-$i));
							echo "<option value=\"".$year."\">".$year."</option>";
						}?>
            </select>
            <script>					
						for(i=0; i<$('caseNoteYear').options.length; i++) {
							if($('caseNoteYear').options[i].value=='<? echo $caseNoteYear ?>') {
								$('caseNoteYear').options[i].selected = true;
							}
						}
					</script>
          </td>
        </tr>
        <tr>
          <td><br></td>
        </tr>
        <tr>
          <td colspan="3"><!-- NESTED TABLE-->
            <table width="100%">
              <tbody>
                <tr>
                  <!-- Case Note Coordinator -->
                  <td><label name="caseNoteCoordinator">Coordinator Creating Case Note</label>
                    <br>
                    <input type="text" style="width: 225px;" value="<?php echo $caseNoteCoordinator ?>"
                    	name="caseNoteCoordinator" id="caseNoteCoordinator">
                  </td>
                  <!-- ARCIL Department -->
                  <td><label name="serviceType">Service Type</label>
                    <br>
                    <select name="serviceType" id="serviceType" style="width: 150px;">
                      <option value=""> --- </option>
                      <?php 
                   // $typeQuery = "select * from lst_service_type";
			$typeQuery = "select * from programs";
                    $result = mysql_query($typeQuery);
                    while($row=mysql_fetch_array($result)) {
						$type_id = $row["program_id"];
						$type = $row["program_name"];
                      if($serviceType==$type_id)
                        echo "<option value=\"".$type_id."\" selected>".$type."</option>";
                      else
                        echo "<option value=\"".$type_id."\">".$type."</option>";
                    }
                  ?>
                    </select>
                    <script>					
						for(i=0; i<$('serviceType').options.length; i++) {
							if($('serviceType').options[i].value=='<? echo $serviceType ?>') {
								$('serviceType').options[i].selected = true;
							}
						}
					</script>
                  </td>
                  <!-- Service Contacts -->
                  <td style="padding-left: 15px;"><label name="totalServiceContacts">Total Number of Contacts</label>
                    <br>
                    <input type="text" style="width: 170px;" name="totalServiceContacts" 
                    	value="<?php echo $totalServiceContacts ?>" id="totalServiceContacts">
                  </td>
                </tr>
                <tr>
                  <td><br>
                  </td>
                </tr>
                <tr>
                  <!-- Service contact Methods-->
                  <td colspan="3"><label name="serviceContactMethods">Contacts Made:</label>
                    <br />
                    <table>
                      <tr>
                        <td><div class="checkBoxUnit">
                            <input name="contactByPhone" type="checkbox" <?php if($contactByPhone==1) echo "checked "?>>
                            By Phone </div></td>
                        <td><div class="checkBoxUnit">
                            <input name="contactByPerson" type="checkbox" 
                        style="margin-left: 40px;" <?php if($contactByPerson==1) echo "checked "?>>
                            In Person </div></td>
                        <td><div class="checkBoxUnit">
                            <input name="contactByMail" type="checkbox" 
                      	style="margin-left: 40px;" <?php if($contactByMail==1) echo "checked "?>>
                            Through Mail </div></td>
                      </tr>
                    </table></td>
                </tr>
              </tbody>
            </table></td>
        </tr>
        <tr>
          <td colspan="3">
		  <label style="margin-left: 5px;">Describe Services Provided</label>
            <br>
            <textarea name="services" cols="110" rows="10"><?php echo $services ?></textarea>
          </td>
        </tr>
        <tr>
          <td colspan="3"><h3>Service Category Statistics</h3></td>
        </tr>
        <tr>
          <td colspan="3"><!-- NESTED TABLE -->
            <table width="100%">
              <tbody>
                <tr class="alt_objective">
                  <th colspan="2">Individual Services</th>
                  <th>Time (Hours)</th>
                </tr>
                <?php 
				#get all service category data
				$category_query = "SELECT * FROM lst_service_category";
				$result = mysql_query($category_query);
				#design flag
				$z=1;
				
				while($row2=mysql_fetch_array($result)) {
					#parse service category types
					$categoryId = $row2["id"];
					$category = $row2["category"];
										
					#link this casenote with the current service category
					$serviceQuery = "SELECT * 
									      FROM monthlyISR_service 
									     WHERE monthlyISR_id = '".$misrId."' 
									     AND service_category_id = '".$categoryId."'";
					$serviceResult = mysql_query($serviceQuery);
					#if we get a match, define the hours
					if($serviceRow = mysql_fetch_array($serviceResult)) {
						$serviceHours = $serviceRow["hours"];
					}else{
						#if no match, set hours to ZERO
						$serviceHours = 0;
					}				
					if($z%2==0) {
						echo "<tr class=\"odd\">";
					} else {
						echo "<tr>";
					}
				?>
                  <td colspan="2"><input name="<?php echo $categoryId ?>_category" id="<?php echo $categoryId ?>_category"
                  	<?php if($serviceRow) echo "checked" ?> type="checkbox">
                    <?php echo $category; ?> </td>
                  <td>
									<input type="text" class="hour" 
                  			name="<?php echo $categoryId ?>_hours" 
												value="<?php echo $serviceHours ?>" 
                                           onkeyup="sumInputs('hour', 'monthlyISRTbl', $('serviceHourTotals')); updateCheckBox($('<?php echo $categoryId ?>_category'))">
                  </td>
                </tr>
                <?php $z++;} ?>
                <tr>
                  <td><br></td>
                </tr>
                <tr>
                  <td colspan="2"><label name="serviceHourTotals">
                    <h4 style="text-align: right;">Total Service Hours</h4>
                    </label>
                  </td>
                  <!-- THIS IS A TEXTBOX NOW, BUT IT SHOULD JUST ECHO THE TOTALS -->
                  <td><input type="text" name="serviceHourTotals" id="serviceHourTotals"
                  				value="<?php echo $serviceHourTotals ?>">
                  </td>
                </tr>
              </tbody>
            </table></td>
        </tr>
        <tr>
          <td><br></td>
        </tr>
        <!-- FORM CONTROLS -->
        <tr>
          <td colspan="3" align="right">
          	<input name="id" type="hidden"  value="<?php echo $id;?>">
            <input name="isrId" type="hidden" value="<?php echo $isrId;?>" />
            <input name="irId" type="hidden" value="<?php echo $irId;?>" />
            <input value="Submit" class="btn" type="submit">
            <input class="btn" type="button" value="Cancel" 
      			onclick="window.location='admin.php?action=cieedit&id=<?php echo $id;?>';"/>
          </td>
        </tr>
      </tbody>
    </table>
  </div>
  <br>
  <br>
</form>
<script>
	sumInputs('hour', 'monthlyISRTbl', $('serviceHourTotals'));
</script>
